/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.audit.aop  
 */
package com.apache.auditRule.server;

import java.lang.reflect.Method;

import org.apache.log4j.Logger;
import org.springframework.aop.AfterReturningAdvice;

import com.apache.api.entity.BaseEntity;
import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;

/**
 * description:  方法执行后的日志通知
 * @author Hou Dayu 创建时间：2014-8-7  
 * @Copyright(c)2014:北京软件技术有限公司
 */
public class AuditMethodAfterPubAssets implements AfterReturningAdvice {

	private Logger log = Logger.getLogger(AuditMethodAfterPubAssets.class);

	/**
	 * TODO 实现方法后拦截. 
	 * @see org.springframework.aop.AfterReturningAdvice#afterReturning(java.lang.Object, java.lang.reflect.Method, java.lang.Object[], java.lang.Object)
	 */
	@SuppressWarnings("rawtypes")
	public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
		//String targetName = target.getClass().getName();
		String methodName = method.getName();
		ParamsVo arguments = (ParamsVo) args[0];
		ParamsVo paramsVo = new ParamsVo<BaseEntity>();
		String flag = (String) arguments.getParams("flag");
		if (("saveInfo".equals(methodName) || "editInfo".equals(methodName)) && Validator.isNotNull(flag)
				&& "1".equals(flag)) {
			paramsVo.setParams("tableName", "t_financial_assets");
			paramsVo.setParams("auditType", "identify");
			paramsVo.setParams("colName", "id");
			paramsVo.setParams("pid", arguments.getParams("pid"));
			paramsVo.setParams("userEname", arguments.getParams("userEname"));
			AuditSaveHelper.newIntance().auditSave(paramsVo);
		} else if (("saveInfo".equals(methodName) || "editInfo".equals(methodName)) && Validator.isNotNull(flag)
				&& "2".equals(flag)) {
			paramsVo.setParams("tableName", "t_financial_assets");
			paramsVo.setParams("auditType", "change");
			paramsVo.setParams("colName", "id");
			paramsVo.setParams("pid", arguments.getParams("pid"));
			paramsVo.setParams("userEname", arguments.getParams("userEname"));
			AuditSaveHelper.newIntance().auditSave(paramsVo);
		}
	}
}
